export function BMapGeocoder () {
  // if (window.AMap) return Promise.resolve()
  return new Promise(function (resolve, reject) {
    var script = document.createElement('script')
    script.type = 'text/javascript'
    script.src =
      'https://api.map.baidu.com/api?type=webgl&v=1.0&ak=HuzmIXcfmPv8RGi4HiXOv55j8QM4IzsM'
    console.log(script)
    script.onerror = e => reject(e)
    script.onload = () => resolve()
    document.head.appendChild(script)
  })
}

export function BM () {
  return new Promise(function (resolve, reject) {
    window.onload = function () {
      // eslint-disable-next-line no-undef
      resolve()
    }
    var script = document.createElement('script')
    script.type = 'text/javascript'
    script.src =
      'https://api.map.baidu.com/api?v=2.0&ak=HuzmIXcfmPv8RGi4HiXOv55j8QM4IzsM'
    script.onerror = reject
    document.head.appendChild(script)
  })
}

export function BMapCircleEditor () {
  // if (window.AMap.CircleEditor) return Promise.resolve()
  return new Promise(function (resolve, reject) {
    var script = document.createElement('script')
    script.type = 'text/javascript'
    script.src =
      'https://webapi.amap.com/maps?v=2.0&key=' +
      'dacb85f968e40b008f30eaadaa9e6ae1' +
      '&plugin=AMap.CircleEditor'
    console.log(script)
    script.onerror = e => reject(e)
    script.onload = () => resolve()
    document.head.appendChild(script)
  })
}
